@page "/docio/word-to-pdf"
@inject Microsoft.JSInterop.IJSRuntime JS
@using System.IO
@using Syncfusion.Blazor.Buttons
@using BlazorDemos.Data.FileFormats.DocIO
@inherits SampleBaseComponent;

<SampleDescription>
    <p style="font-size:16px"> This sample explains how to convert Word document to PDF using Essential DocIO and Essential PDF.</p>
</SampleDescription>
<ActionDescription>
    <p style="font-size:16px">DocIO provides support to render Word document from flow to fixed page model and export as PDF or Image. With this support to render Word document,</p>
    <p><ul style="font-size:16px"><li>You can generate invoice and other reports in PDF, starting from Word document.</li><li>You can view or print the contents of Word document by converting as PDF and loading generated PDF via PDF viewer.</li></ul></p>
    <p style="font-size:16px">More information about the nested Mail merge can be found in this <a href="https://help.syncfusion.com/file-formats/docio/word-to-pdf">documentation</a> section.</p>
</ActionDescription>

<div class="control-section">
    <p style="font-size:16px">Click the button to view the generated Word document. Please note that Microsoft Word Viewer or Microsoft Word is required to view the resultant Word document.</p>
    <div class="checkbox-control">
        <div class="row">
            <SfCheckBox @bind-Checked="@preserveStructureTags" Label="Preserve structure tags, generates PDF document with accessiblity support." ></SfCheckBox>
        </div>
        <div class="row">
            <SfCheckBox @bind-Checked="@preserveFormFields" Label="Preserve form fields, generates PDF document with PDF form fields for equivalent Word document form fields."></SfCheckBox>
        </div>
        <div class="row">
            <SfCheckBox @bind-Checked="@preserveWordHeadingsToPDFBookmarks" Label="Convert Word headings to PDF bookmarks, generates PDF document with bookmarks for Word document paragraph with heading style and outline level."></SfCheckBox>
        </div>
        <div class="row">
            <SfCheckBox @bind-Checked="@showRevisions" Label="Show the revision marks in the generated PDF for tracked changes or revisions in the Word document."></SfCheckBox>
        </div>
    </div>
    <div class="button-section">
        <div id="button-control">
            <div class="row">
                <div>
                    <SfButton @onclick="ViewTemplate">View Template</SfButton>&nbsp;
                    <SfButton @onclick="GenerateDocument">Convert to PDF</SfButton>
                </div>
            </div>
        </div>
    </div>
</div>

<style>
    .control-section .row {
        margin: 10px 0;
    }
</style>

@code {
    MemoryStream documentStream;
    bool preserveStructureTags, showRevisions;
    bool preserveFormFields = true;
    bool preserveWordHeadingsToPDFBookmarks = true ; 

    /// <summary>
    /// Create and download the simple Word document
    /// </summary>
    public async Task GenerateDocument(MouseEventArgs args)
    {
        WordToPDFService service = new WordToPDFService();
        documentStream = service.WordToPDF("Generate Document", preserveStructureTags, preserveFormFields, preserveWordHeadingsToPDFBookmarks, showRevisions);
        await JS.SaveAs("WordToPDF.pdf", documentStream.ToArray());
    }
    /// <summary>
    /// Create and download the template Word document
    /// </summary>
    public async Task ViewTemplate(MouseEventArgs args)
    {
        WordToPDFService service = new WordToPDFService();
        documentStream = service.WordToPDF("View Template", preserveStructureTags, preserveFormFields, preserveWordHeadingsToPDFBookmarks, showRevisions);
        await JS.SaveAs("WordToPDF.docx", documentStream.ToArray());
    }
}